--[[/**
-- * 
 * 根据距离 减/加 属性
 * [最大距离,属性id,属性最大值]
-- *
-- */]]

---@class BuffEffect575100 : BaseBuffEffect
BuffEffect575100 = ClientFight.CreateClass("BuffEffect575100", ClientFight.BaseBuffEffect)
local t = BuffEffect575100
t.BuffEffect575100_DIS = "BuffEffect575100_DIS";

function t:add(fight, buff)
    t:attri(fight, buff);
    return ClientFight.BaseBuffEffect.add(self, fight, buff);
end

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local attri = t:attri(fight, buff);
    ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
    if (attri) then
        return IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE;
    else
        return IBuffEffect.SUCCESS_ATTRI_NO_CHANGE;
    end
end

function t:attri(fight, buff)
    local distance = DistanceUtil.countDistance(buff.source.position, buff.target.position);
    local buffEffectValue = buff.buffBean.f_BuffEffectValueTemp;
    local disLimit = Utils.toRatio(buffEffectValue[1]);
    local o = buff.effectParams[t.BuffEffect575100_DIS];
    local step = math.ceil(math.abs(disLimit - distance));
    if (o ~= null) then
        local oldDis = o;
        if (oldDis == step) then
            return false;
        end
    else
        if (distance >= disLimit) then
            return false;
        end
    end
    buff.effectParams[t.BuffEffect575100_DIS] = step;
    if (distance >= disLimit) then
        buff.attributes.attributes = {};
        return true;
    end

    for i = 2, table.getn(buffEffectValue), 2 do
        local attrType = buffEffectValue[i];
        local attrLimit = buffEffectValue[i + 1];
        local value = (attrLimit / disLimit * step);
        buff.attributes.attributes[attrType] = value;
        SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s buff%s 距离变化导致属性发生改变, %s = %s ",
                fight.frame, buff.target.fighterId, buff.modelId, attrType, value));
    end
    return true;
end

t.New()